<?php
/**
 * Created by PhpStorm.
 * User: HM22
 * Date: 2019/5/14
 * Time: 14:27
 */

namespace app\admin\inter_model;

use app\inter\model\InterBase;
use think\Model;
use think\Db;

class CarRouteModel extends InterBase
{
    public function addRoute($data)
    {
        return Db::table('inter_car_route')->insertGetId($data);
    }

    public function updateRoute($map,$data)
    {
        return Db::table('inter_car_route')->where($map)->update($data);
    }

    public function getRouteList($map,$field='cr.*',$page=1,$limit=10,$config='')
    {
        $config = $config?:$this->config;

        return Db::connect($config)->name('car_route cr')
            ->join('arean s','cr.start_address=s.id','LEFT')
            ->join('arean e','cr.end_address=e.id','LEFT')
            ->join('rail r1','r1.id=cr.start_rail_id','LEFT')
            ->join('rail r2','r2.id=cr.end_rail_id', 'LEFT')
            ->where($map)
            ->field($field)
            ->page($page,$limit)
            ->order('cr.id desc')->select();
    }

    public function searchRoute($map,$field='*',$config='')
    {
        return Db::table('inter_car_route')->where($map)->field($field)->find();
    }

    public function deleteRoute($map)
    {
        return Db::table('inter_car_route')->where($map)->delete();
    }

//    public function getCarBanciGroup($map,$field='*',$group='')
//    {
//        if(empty($group)){
//            return false;
//        }
//        return Db::table('inter_car_banci')->where($map)->field($field)->group($group)->select();
//    }

}